package com.maxchaintech.integral.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.maxchaintech.integral.domain.IntegralDetail;
import com.maxchaintech.integral.service.IIntegralDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.maxchaintech.common.log.annotation.Log;
import com.maxchaintech.common.log.enums.BusinessType;
import com.maxchaintech.common.security.annotation.PreAuthorize;
import com.maxchaintech.common.core.web.controller.BaseController;
import com.maxchaintech.common.core.web.domain.AjaxResult;
import com.maxchaintech.common.core.utils.poi.ExcelUtil;
import com.maxchaintech.common.core.web.page.TableDataInfo;

/**
 * 积分记录明细Controller
 * 
 * @author jyw
 * @date 2021-04-23
 */
@RestController
@RequestMapping("/detail")
public class IntegralDetailController extends BaseController
{
    @Autowired
    private IIntegralDetailService integralDetailService;

    /**
     * 查询积分记录明细列表
     */
    @PreAuthorize(hasPermi = "integral:detail:list")
    @GetMapping("/list")
    public TableDataInfo list(IntegralDetail integralDetail)
    {
        startPage();
        List<IntegralDetail> list = integralDetailService.selectIntegralDetailList(integralDetail);
        return getDataTable(list);
    }

    /**
     * 导出积分记录明细列表
     */
    @PreAuthorize(hasPermi = "integral:detail:export")
    @Log(title = "积分记录明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IntegralDetail integralDetail) throws IOException
    {
        List<IntegralDetail> list = integralDetailService.selectIntegralDetailList(integralDetail);
        ExcelUtil<IntegralDetail> util = new ExcelUtil<IntegralDetail>(IntegralDetail.class);
        util.exportExcel(response, list, "积分记录明细数据");
    }

    /**
     * 获取积分记录明细详细信息
     */
    @PreAuthorize(hasPermi = "integral:detail:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(integralDetailService.selectIntegralDetailById(id));
    }

    /**
     * 新增积分记录明细
     */
    @PreAuthorize(hasPermi = "integral:detail:add")
    @Log(title = "积分记录明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IntegralDetail integralDetail)
    {
        return toAjax(integralDetailService.insertIntegralDetail(integralDetail));
    }

    /**
     * 修改积分记录明细
     */
    @PreAuthorize(hasPermi = "integral:detail:edit")
    @Log(title = "积分记录明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IntegralDetail integralDetail)
    {
        return toAjax(integralDetailService.updateIntegralDetail(integralDetail));
    }

    /**
     * 删除积分记录明细
     */
    @PreAuthorize(hasPermi = "integral:detail:remove")
    @Log(title = "积分记录明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(integralDetailService.deleteIntegralDetailByIds(ids));
    }
}
